package com.example.news;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;


import com.example.news.bean.OneBean;
import com.example.news.fragment.ChangshangFragment;
import com.example.news.fragment.FangChanFragment;
import com.example.news.fragment.Fragment_one;
import com.example.news.fragment.Fragment_three;
import com.example.news.fragment.Fragment_two;
import com.example.news.fragment.JianKangFragment;
import com.example.news.fragment.KeJiFragment;
import com.example.news.fragment.RendianActivity;
import com.example.news.fragment.ShouchangFragment;
import com.example.news.fragment.YuleiFragment;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private RelativeLayout bb;
    private LinearLayout page;
    private ImageView shouye;
    private ImageView shipin;
    private ImageView wode;
    private LinearLayout aa;
    private FragmentTransaction fragmentManager;
    private Fragment fragment_one, fragment_two, fragment_three,text,changshang,yule,fangchang,keji,jiankang,shoucheng;
    private LinearLayout line;
    private ArrayList<View> list;
    private EditText edit_top;
    private ArrayList<OneBean>list1=new ArrayList<>();
    Intent intent;
    private ImageView ooo;
    private TextView q;
    private TextView w;
    private TextView e;
    private TextView r;
    private TextView t;
    private TextView y;
    private TextView u;
    private TextView i;
    private TextView o;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); //隐藏状态栏
        InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
        View view = getWindow().peekDecorView();
        if (view != null) {
            edit_top.clearFocus();
            inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }


    }

    private void initView() {
        list = new ArrayList<>();
        bb = findViewById(R.id.bb);

        shouye = findViewById(R.id.shouye);
        shipin = findViewById(R.id.shipin);
        wode = findViewById(R.id.wode);
        aa = (LinearLayout) findViewById(R.id.aa);
        line = (LinearLayout) findViewById(R.id.line);
        edit_top = findViewById(R.id.edit_top);
        // edit_top.clearFocus();

        fragmentManager = getSupportFragmentManager().beginTransaction();
        fragment_one = new Fragment_one();
        shoucheng=new ShouchangFragment();
        fragment_two = new Fragment_two();
        fragment_three = new Fragment_three();
        changshang=new ChangshangFragment();
        yule=new YuleiFragment();
        fangchang=new FangChanFragment();
        keji=new KeJiFragment();
        jiankang=new JianKangFragment();
        text=new RendianActivity();
        fragmentManager.replace(R.id.line, fragment_one);
        fragmentManager.commit();
        shouye.setOnClickListener(this);
        shipin.setOnClickListener(this);
        wode.setOnClickListener(this);

        intent = getIntent();
        if (intent.getStringExtra("name") != null) {
            fragmentManager = getSupportFragmentManager().beginTransaction();
            fragmentManager.replace(R.id.line, fragment_three);
            fragmentManager.commit();
            shipin.setImageResource(R.drawable.shipin);
            wode.setImageResource(R.drawable.wode2);
            shouye.setImageResource(R.drawable.shouyeer);
        }

        ooo = (ImageView) findViewById(R.id.ooo);
        ooo.setOnClickListener(this);
        q = (TextView) findViewById(R.id.q);
        q.setOnClickListener(this);
        w = (TextView) findViewById(R.id.w);
        w.setOnClickListener(this);
        e = (TextView) findViewById(R.id.e);
        e.setOnClickListener(this);
        r = (TextView) findViewById(R.id.r);
        r.setOnClickListener(this);
        t = (TextView) findViewById(R.id.t);
        t.setOnClickListener(this);
        y = (TextView) findViewById(R.id.y);
        y.setOnClickListener(this);
        u = (TextView) findViewById(R.id.u);
        u.setOnClickListener(this);
        i = (TextView) findViewById(R.id.i);
        i.setOnClickListener(this);
        o = (TextView) findViewById(R.id.o);
        o.setOnClickListener(this);
        page=findViewById(R.id.page);
    }



    public String aa() {
        String name = intent.getStringExtra("name");
        if (name!=null){
            page.setVisibility(View.GONE);
        }
        return name;
    }
    public Fragment_one getFragment_ont(){
        return (Fragment_one) fragment_one;
    }


    @Override
    public void onClick(View view) {
        fragmentManager = getSupportFragmentManager().beginTransaction();//获取Fragment
        switch (view.getId()) {//点击选项
            case R.id.shipin:
                fragmentManager.replace(R.id.line, fragment_two);  //替换Fragment
                shipin.setImageResource(R.drawable.shipin2);
                wode.setImageResource(R.drawable.wode);
                shouye.setImageResource(R.drawable.shouyeer);
                page.setVisibility(View.VISIBLE);//显示滑动布局
                break;
            case R.id.shouye:
                fragmentManager.replace(R.id.line, fragment_one);
                shipin.setImageResource(R.drawable.shipin);
                wode.setImageResource(R.drawable.wode);
                shouye.setImageResource(R.drawable.shouye);
                page.setVisibility(View.VISIBLE);
                break;
            case R.id.wode:
                fragmentManager.replace(R.id.line, fragment_three);
                shipin.setImageResource(R.drawable.shipin);
                wode.setImageResource(R.drawable.wode2);
                shouye.setImageResource(R.drawable.shouyeer);
                page.setVisibility(View.GONE);
                break;
            case R.id.q:
                q.setTextColor(Color.RED);
                w.setTextColor(Color.BLACK);
                e.setTextColor(Color.BLACK);
                r.setTextColor(Color.BLACK);
                t.setTextColor(Color.BLACK);
                y.setTextColor(Color.BLACK);
                u.setTextColor(Color.BLACK);
                i.setTextColor(Color.BLACK);
                o.setTextColor(Color.BLACK);
                page.setVisibility(View.VISIBLE);
                fragmentManager.replace(R.id.line, shoucheng);
                break;
            case R.id.w:
                page.setVisibility(View.VISIBLE);
                w.setTextColor(Color.RED);
                q.setTextColor(Color.BLACK);
                e.setTextColor(Color.BLACK);
                r.setTextColor(Color.BLACK);
                t.setTextColor(Color.BLACK);
                y.setTextColor(Color.BLACK);
                u.setTextColor(Color.BLACK);
                i.setTextColor(Color.BLACK);
                o.setTextColor(Color.BLACK);
                fragmentManager.replace(R.id.line, fragment_one);
                break;
            case R.id.e:
                page.setVisibility(View.VISIBLE);
                e.setTextColor(Color.RED);
                w.setTextColor(Color.BLACK);
                q.setTextColor(Color.BLACK);
                r.setTextColor(Color.BLACK);
                t.setTextColor(Color.BLACK);
                y.setTextColor(Color.BLACK);
                u.setTextColor(Color.BLACK);
                i.setTextColor(Color.BLACK);
                o.setTextColor(Color.BLACK);
                fragmentManager.replace(R.id.line, fragment_two);

                break;
            case R.id.r:
                fragmentManager.replace(R.id.line, text);
                page.setVisibility(View.VISIBLE);
                e.setTextColor(Color.BLACK);
                w.setTextColor(Color.BLACK);
                q.setTextColor(Color.BLACK);
                r.setTextColor(Color.RED);
                t.setTextColor(Color.BLACK);
                y.setTextColor(Color.BLACK);
                u.setTextColor(Color.BLACK);
                i.setTextColor(Color.BLACK);
                o.setTextColor(Color.BLACK);
                break;
            case R.id.t:
                fragmentManager.replace(R.id.line, changshang);
                page.setVisibility(View.VISIBLE);
                e.setTextColor(Color.BLACK);
                w.setTextColor(Color.BLACK);
                q.setTextColor(Color.BLACK);
                r.setTextColor(Color.BLACK);
                t.setTextColor(Color.RED);
                y.setTextColor(Color.BLACK);
                u.setTextColor(Color.BLACK);
                i.setTextColor(Color.BLACK);
                o.setTextColor(Color.BLACK);
                break;
            case R.id.y:
                fragmentManager.replace(R.id.line, yule);
                page.setVisibility(View.VISIBLE);
                e.setTextColor(Color.BLACK);
                w.setTextColor(Color.BLACK);
                q.setTextColor(Color.BLACK);
                r.setTextColor(Color.BLACK);
                t.setTextColor(Color.BLACK);
                y.setTextColor(Color.RED);
                u.setTextColor(Color.BLACK);
                i.setTextColor(Color.BLACK);
                o.setTextColor(Color.BLACK);
                break;
            case R.id.u:
                fragmentManager.replace(R.id.line, fangchang);
                page.setVisibility(View.VISIBLE);
                e.setTextColor(Color.BLACK);
                w.setTextColor(Color.BLACK);
                q.setTextColor(Color.BLACK);
                r.setTextColor(Color.BLACK);
                t.setTextColor(Color.BLACK);
                y.setTextColor(Color.BLACK);
                u.setTextColor(Color.RED);
                i.setTextColor(Color.BLACK);
                o.setTextColor(Color.BLACK);
                break;
            case R.id.i:
                fragmentManager.replace(R.id.line, keji);
                page.setVisibility(View.VISIBLE);
                e.setTextColor(Color.BLACK);
                w.setTextColor(Color.BLACK);
                q.setTextColor(Color.BLACK);
                r.setTextColor(Color.BLACK);
                t.setTextColor(Color.BLACK);
                y.setTextColor(Color.BLACK);
                u.setTextColor(Color.BLACK);
                i.setTextColor(Color.RED);
                o.setTextColor(Color.BLACK);
                break;
            case R.id.o:
                fragmentManager.replace(R.id.line, jiankang);
                page.setVisibility(View.VISIBLE);
                e.setTextColor(Color.BLACK);
                w.setTextColor(Color.BLACK);
                q.setTextColor(Color.BLACK);
                r.setTextColor(Color.BLACK);
                t.setTextColor(Color.BLACK);
                y.setTextColor(Color.BLACK);
                u.setTextColor(Color.BLACK);
                i.setTextColor(Color.BLACK);
                o.setTextColor(Color.RED);
                break;

        }
        fragmentManager.commit();

    }
}
